﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

namespace EFong.Contract
{
    [DataContract]
    public class TrainTicketReturn : Order
    {
        public TrainTicketReturn()
        {
            OrderType = "火车票退票";
        }

        private int _qty;
        [DataMember]
        public int Qty
        {
            get { return _qty; }
            set { _qty = value; }
        }

        private decimal _serviceCharge;
        [DataMember]
        public decimal ServiceCharge
        {
            get { return _serviceCharge; }
            set { _serviceCharge = value; }
        }

        private decimal _vendorServiceCharge;
        [DataMember]
        public decimal VendorServiceCharge
        {
            get { return _vendorServiceCharge; }
            set { _vendorServiceCharge = value; }
        }

        private decimal _customerReturn;
        [DataMember]
        public decimal CustomerReturn
        {
            get { return _customerReturn; }
            set { _customerReturn = value; }
        }

        private decimal _vendorReturn;
        [DataMember]
        public decimal VendorReturn
        {
            get { return _vendorReturn; }
            set { _vendorReturn = value; }
        }

        private Currency _currency;
        [DataMember]
        public Currency Currency
        {
            get { return _currency; }
            set { _currency = value; }
        }

        private Vendor _vendor;
        [DataMember]
        public Vendor Vendor
        {
            get { return _vendor; }
            set { _vendor = value; }
        }

        private Customer _customer;
        [DataMember]
        public Customer Customer
        {
            get { return _customer; }
            set { _customer = value; }
        }

        private Currency _vendorCurrency;
        [DataMember]
        public Currency VendorCurrency
        {
            get { return _vendorCurrency; }
            set { _vendorCurrency = value; }
        }

        private decimal _exchangeRate = 1;
        [DataMember]
        public decimal ExchangeRate
        {
            get { return _exchangeRate; }
            set { _exchangeRate = value; }
        }

        public decimal Profit 
        {
            get 
            {
                if (this.Currency != this.VendorCurrency) 
                    return VendorReturn - CustomerReturn + ServiceCharge - VendorServiceCharge * ExchangeRate;
                else
                    return VendorReturn - CustomerReturn + ServiceCharge - VendorServiceCharge;
            }
        }

        public override bool Equals(object obj)
        {
            TrainTicketReturn temp = obj as TrainTicketReturn;
            if (temp == null)
                return false;
            return (this.ID.Equals(temp.ID));
        }
    }
}
